#ifndef INTERFACE_VIEW_HPP
#define INTERFACE_VIEW_HPP

#include "Widget.hpp"
#include "Utils/Log.hpp"
#include <deque>

namespace mi
{
    enum ViewOrientation
    {
        Horizontal,
        Vertical,
        None    // has no effect - does not change orientation of View
    };

    class View : public Widget
    {
    public:
        View (ViewOrientation orient = Vertical);

        // override the function to check what it contains

        bool Contains(Widget* other);

        // Override input functions

        Widget* MouseClick(sf::Mouse::Button button, sf::MouseState state, int x, int y);
        
        Widget* MouseMoved(int x, int y, int dx, int dy);
        
        Widget* MouseDragged(int x, int y, int dx, int dy);
        
        Widget* MouseWheel(int dir);
        
        Widget* KeysDown(sf::Event::KeyEvent key);
        
        Widget* KeysUp(sf::Event::KeyEvent key);

        Widget* TextEntered(char ch);

        // View specific functions
        
        View& AddWidget (Widget *toAdd, int weight = 1);

        View& RemoveWidget (Widget *toRemove);

        Widget* FindWidget (std::string ID);

        ViewOrientation Orientation (ViewOrientation orient = None);

        // Overwrite the onMove and onResize functions

        void OnSizeChange(Vec2i oldSize);

        void OnPositionChange(Vec2i oldPosition);

        // Overwrite the pure virtuals from Widget

        void Draw2D ();

        bool Update (double dTime);

    private:    
        struct Member
        {
            Member(Widget *wid, int wei) : widget(wid), weight(wei) { }
            Widget *widget;
            int weight;
        };

        void Reorganize ();

        void ReorganizeHorizontally ();

        void ReorganizeVertically ();

        int GetWeightSum ();

        ViewOrientation orientation;
        
        std::deque<Member> widgetList;

        int horSpacing, verSpacing;

        int horPadding, verPadding;

        bool needToReorganize;
    };
}

#endif